package utils

import (
	"context"
	"crypto/md5"
	"fmt"
	"io"
)

// PasswordEncrypt 密码加密
func PasswordEncrypt(value string) string {
	h := md5.New()
	io.WriteString(h, value)
	pwdMd5 := fmt.Sprintf("%x", h.Sum(nil))
	io.WriteString(h, pwdMd5)
	return fmt.Sprintf("%x", h.Sum(nil))
}

// GetValueByContext 从context中获取数据
func GetValueByContext[T any](ctx context.Context, key string) T {
	return ctx.Value(key).(T)
}
